package com.ming.controller;

import com.ming.pojo.Dept;
import com.ming.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptConsumerController {

    //这里直接把springcloud-api的DeptClientService接口注入进来
    @Autowired
    private DeptClientService deptClientService = null;

    //然后通过接口来调用方法，调用方法后，它会调用上面类对应的方法，最后调用其服务名字的接口
    @RequestMapping("/consumer/dept/get/{id}")
    @ResponseBody
    public Dept queryById(@PathVariable("id") Long id) {
        return this.deptClientService.queryById(id);
    }

    @RequestMapping("/consumer/dept/add")
    @ResponseBody
    public boolean add(Dept dept) {
        return this.deptClientService.addDept(dept);
    }

    @RequestMapping("/consumer/dept/list")
    @ResponseBody
    public List<Dept> queryAll() {
        return this.deptClientService.queryAll();
    }

}
